package com.russell.pms.dao.hibernate;

import java.util.List;

import com.russell.pms.dao.PaymentDao;
import com.russell.pms.model.Payment;

/**
 * 
 * @author <a href="mailto:fvinluan@gmail.com">Francis Vinluan</a>
 * 
 * @version $Revision: 1.0 $
 */
public class PaymentDaoHibernate extends BaseDaoHibernate implements PaymentDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#getPayment(java.lang.Short)
	 */
	/**
	 * Method getPayment.
	 * 
	 * @param id
	 *            Long
	 * 
	 * @return Payment * @see com.princess.etrak.dao.PaymentDao#getPayment(Long)
	 *         * @see com.princess.etrak.dao.PaymentDao#getPayment(String) * @see
	 *         com.princess.etrak.dao.PaymentDao#getPayment(String)
	 */
	public Payment getPayment(int id) {
		if (logger.isDebugEnabled()) {
			logger.debug("getting payment begins" + id);
		}
		Payment payment = (Payment) getCurrentSession().get(Payment.class, id);
		if (logger.isDebugEnabled()) {
			logger.debug("getting payment ends ");
		}
		return payment;
	}

	/**
	 * Gets a list of all payment.
	 * 
	 * 
	 * @return List populated list of payment * @see
	 *         com.princess.etrak.dao.PaymentDao#getPaymentList() * @see
	 *         com.princess.etrak.dao.PaymentDao#getPaymentList() * @see
	 *         com.princess.etrak.dao.PaymentDao#getPaymentList() * @see
	 *         com.princess.etrak.dao.PaymentDao#getPaymentList()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Payment> getPayments() {
		if (logger.isDebugEnabled()) {
			logger.debug("getting all payment begins");
		}
		List<Payment> cList = getCurrentSession().createQuery("FROM Payment")
				.list();
		if (cList == null || cList.size() < 1)
			return null;
		if (logger.isDebugEnabled()) {
			logger.debug("getting all payment ends: ");
		}
		return cList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#removePayment(com.princess.ilo
	 * .model.Payment)
	 */
	/**
	 * Method removePayment.
	 * 
	 * @param payment
	 *            Payment
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#removePayment(Payment)
	 */
	public void removePayment(Payment payment) {
		if (logger.isDebugEnabled()) {
			logger.debug("removePayment begins");
		}
		getCurrentSession().delete(payment);
		if (logger.isDebugEnabled()) {
			logger.debug("removePayment ends");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#savePayment(com.princess.etrak.
	 * model.Payment)
	 */
	/**
	 * Method savePayment.
	 * 
	 * @param payment
	 *            Payment
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#savePayment(Payment)
	 */
	public void savePayment(Payment payment) {
		if (logger.isDebugEnabled()) {
			logger.debug("savePayment begins: " + payment);
		}
		getCurrentSession().save(payment);
		if (logger.isDebugEnabled()) {
			logger.debug("savePayment ends");
		}
	}

	/**
	 * Method updatePayment.
	 * 
	 * @param payment
	 *            Payment
	 * 
	 * @see com.princess.etrak.dao.PaymentDao#updatePayment(Payment)
	 */
	@Override
	public void updatePayment(Payment payment) {
		if (logger.isDebugEnabled()) {
			logger.debug("updatePayment begins: " + payment);
		}
		getCurrentSession().update(payment);
		if (logger.isDebugEnabled()) {
			logger.debug("updatePayment ends");
		}
	}

}
